using System.Collections.Generic;

namespace JGSY.CMS.LowCode.Platform.Application.DTOs
{
    /// <summary>
    /// 分页查询结果
    /// 通用的分页返回数据结构
    /// </summary>
    /// <typeparam name="T">数据类型</typeparam>
    public class PagedResultDto<T>
    {
        /// <summary>
        /// 当前页数据列表
        /// </summary>
        public IEnumerable<T> Items { get; set; } = new List<T>();
        
        /// <summary>
        /// 总记录数
        /// </summary>
        public int TotalCount { get; set; }
        
        /// <summary>
        /// 当前页码
        /// </summary>
        public int PageIndex { get; set; }
        
        /// <summary>
        /// 每页记录数
        /// </summary>
        public int PageSize { get; set; }
        
        /// <summary>
        /// 总页数
        /// </summary>
        public int TotalPages => PageSize > 0 ? (int)System.Math.Ceiling((double)TotalCount / PageSize) : 0;
        
        /// <summary>
        /// 是否有上一页
        /// </summary>
        public bool HasPreviousPage => PageIndex > 1;
        
        /// <summary>
        /// 是否有下一页
        /// </summary>
        public bool HasNextPage => PageIndex < TotalPages;
        
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="items">当前页数据</param>
        /// <param name="totalCount">总记录数</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页大小</param>
        public PagedResultDto(IEnumerable<T> items, int totalCount, int pageIndex, int pageSize)
        {
            Items = items;
            TotalCount = totalCount;
            PageIndex = pageIndex;
            PageSize = pageSize;
        }
        
        /// <summary>
        /// 默认构造函数
        /// </summary>
        public PagedResultDto() { }
    }
}
